#@adminLayout() #define main()
<link href="#(ctx)/static/ajax/libs/jasny/jasny-bootstrap.min.css"
	rel="stylesheet" />
<script src="#(ctx)/static/ajax/libs/jasny/jasny-bootstrap.min.js"></script>

<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form id="form-edit" method="post" class="form-horizontal m"
			enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-sm-2 control-label">编码：</label>
				<div class="col-sm-4">
					<input name="ccode" id="ccode" class="form-control" type="text"
						required maxlength="10">
				</div>
				<label class="col-sm-2 control-label">设备编码前缀：</label>
				<div class="col-sm-4">
					<input name="prefix" id="prefix" class="form-control" type="text"
						required maxlength="4">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">名称：</label>
				<div class="col-sm-10">
					<input name="cname" class="form-control" type="text" required
						maxlength="20">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">项目名称：</label>
				<div class="col-sm-10">
					<input name="cproname" class="form-control" type="text" required
						maxlength="20">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">logo图标(220*60)</label>
				<div class="col-sm-10 fileinput fileinput-new"
					data-provides="fileinput">
					<div class="fileinput-new thumbnail"
						style="width: 220px; height: 60px;">
						<img id="img_src"> <input type="hidden" name="logo_src" />
					</div>
					<div class="fileinput-preview fileinput-exists thumbnail"
						style="max-width: 280px; max-height: 200px;"></div>
					<div>
						<span class="btn btn-white btn-file"><span
							class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span>
							<input type="file" name="img_src" accept=".png"></span> <a
							href="#" class="btn btn-white fileinput-exists"
							data-dismiss="fileinput">清除</a>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">DCS网关：</label>
				<div class="col-sm-4">
					<input name="ip_dcs" class="form-control" type="text" required
						maxlength="20">
				</div>
				<label class="col-sm-2 control-label">DAS网关：</label>
				<div class="col-sm-4">
					<input name="ip_das" class="form-control" type="text" required
						maxlength="20">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">负责人：</label>
				<div class="col-sm-4">
					<input name="cmanager" class="form-control" type="text" required
						maxlength="20">
				</div>
				<label class="col-sm-2 control-label">负责人电话：</label>
				<div class="col-sm-4">
					<input name="cphone" class="form-control" type="text" required
						maxlength="20">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">邮箱：</label>
				<div class="col-sm-4">
					<input name="email" class="form-control" type="email" required
						maxlength="20">
				</div>
				<label class="col-sm-2 control-label">使用情况：</label>
				<div class="col-sm-4">
					<select name="cflag" class="form-control">
						<option value="0">禁用</option>
						<option value="1">有效使用</option>
						<option value="2">长期使用</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">地址：</label>
				<div class="col-sm-10">
					<input name="address" class="form-control" type="text" required
						maxlength="100">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">有效开始：</label>
				<div class="col-sm-4">
					<input name="limitstart" class="form-control time-input"
						type="text" required>
				</div>
				<label class="col-sm-2 control-label">有效结束：</label>
				<div class="col-sm-4">
					<input name="limitend" class="form-control time-input" type="text"
						required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">时序数据库类型：</label>
				<div class="col-sm-4">
					<select name="db_type" class="form-control">
						<option value="TSDB">TSDB</option>
						<option value="Postgres">Postgres</option>
						<option value="MYSQL">MYSQL</option>
					</select>
				</div>
				<label class="col-sm-2 control-label">允许测点数：</label>
				<div class="col-sm-4">
				<input type="number" name="nmax_cd" class="form-control" required />
<!-- 					<input name="nmax_cd" class="form-control" type="number" required> -->
				</div>
			</div>

		</form>
	</div>
	<script type="text/javascript">
		var prefix = "#(ctx)/sysorginfo";
		var ccode = '#(ccode)';
		var ctype = '#(ctype)';
		$(function() {
			jQuery.validator.addMethod("isChar", function(value, element) {
				var ischar = /^[a-zA-Z\d]+$/;
				return this.optional(element) || (ischar.test(value));
			}, "请输入大小写字母和数字");

			jQuery.validator.addMethod("isBigChar", function(value, element) {
				var isBigChar = /^[A-Z]+$/;
				return this.optional(element) || (isBigChar.test(value));
			}, "请输入大写字母");

			$("#form-edit").validate({
				rules : {
					cphone : {
						isPhone : true
					},
					ccode : {
						isChar : true
					},
					prefix : {
						isBigChar : true
					}
				},
				messages : {
					cphone : {
						isPhone : '请出入手机号'
					},
					ccode : {
						regex : "必须字符数字"
					},
					prefix : {
						regex : "必须大写字母"
					}
				}
			});

			$.validator.addMethod("ccode", function(value, element) {
				var reg = /^[a-zA-Z\d]+$/;
				return this.optional(element) || (reg.test(value));
			}, "必须大小写字母数字");

			$.validator.addMethod("prefix", function(value, element) {
				var reg = /^[A-Z]+$/;
				return this.optional(element) || (reg.test(value));
			}, "必须大写字母");

			if (ctype == 'edit') {
				$('#ccode').attr("readonly", "readonly");
				$('#prefix').attr("readonly", "readonly");
			}

			if (ccode) {
				$.ajax({
					type : "POST",
					url : prefix + "/getData",
					data : {
						ccode : ccode
					},
					dataType : 'json',
					success : function(data) {
						$('#form-edit').loadData(data);
						$("#img_src").attr('src',
								'#(webServer)/upload/' + data.logo_src);
					}
				});

				/* 
				$.getJSON(prefix + "/getData",{ccode :ccode},function(data){
				   	$('#form-edit').loadData(data);
					$("#logo_src").attr('src','#(ctx)/upload/'+data.logo_src);
				}); */
				//$('#form-edit').loadForm(prefix+'/getData?ccode='+ccode);
			}
		});

		function submitHandler() {
			if ($.validate.form()) {
				var dataJson = $('#form-edit').serializeArray();
				dataJson.push({
					"name" : "ctype",
					"value" : ctype
				});

				var options = {
					dataType : "json",
					url : prefix + "/save",
					data : dataJson,
					success : function(data) {
						$.operate.successCallback(data);
					}
				};
				$("#form-edit").ajaxSubmit(options);
			}
		}
	</script>
</body>
#end
